﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Objects;
using System.Linq;
using System.Text;
using PowerBooking.RSE.IRepository;

namespace PowerBooking.RSE.Domain.Factories
{
    /// <summary>
    /// 工厂基类
    /// </summary>
    public abstract class Factory
    {
        protected ObjectContext Context { get; set; }

        private readonly Lazy<ISpiderRepository> spiderRepository;
        private readonly Lazy<ICityRepository> cityRepository;
        private readonly Lazy<IFilterRepository> filterRepository;
        private readonly Lazy<IRestaurantRepository> restaurantRepository;

        protected ISpiderRepository SpiderRepository { get { return spiderRepository.Value; } }
        protected ICityRepository CityRepository { get { return cityRepository.Value; } }
        protected IFilterRepository FilterRepository { get { return filterRepository.Value; } }
        protected IRestaurantRepository RestaurantRepository { get { return restaurantRepository.Value; } }

        public Factory(ObjectContext objectContext)
        {
            this.Context = objectContext;
            spiderRepository = new Lazy<SpiderRepository>(() => new SpiderRepository(this.Context));
            cityRepository = new Lazy<CityRepository>(() => new CityRepository(this.Context));
            filterRepository = new Lazy<FilterRepository>(() => new FilterRepository(this.Context));
            restaurantRepository = new Lazy<RestaurantRepository>(() => new RestaurantRepository(this.Context));
        }
    }
}
